// pages/wallet/index.js
var app = getApp(), fetchApi = require("../../../utils/httpPost.js");
import Toast from '../../../component/vant/toast/toast';
Page({
    /**
     * 页面的初始数据
     */
    data: {
        accountList:[],
        pageIndex:1,
        pageSize:20,
        recordList:[],
        hasData:false,
        current: 0,
        duration: 800,
        autoplay: !0,
        interval: 4000,
        indicatorDots: !1,
        circular: !0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.onHttpInit();
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
      this.data.pageIndex = 1;
      this.setData({
        hasData:false,
        recordList:[],
      })
      this.onHttpRecord();
    },
    /**
     * 获取页面数据的 http请求
     */
    onHttpInit: function () {
        var that = this
        fetchApi.httpPost('/account/detail', {}, function (res) {
        console.log("账号数据", res)
        if(res.data.code == 0){
            var accountList = res.data.data;
            that.setData({
                accountList: accountList,
            })
        }
        that.setData({
            netWork: true,
        })
        }, function () {
            that.setData({ netWork: false, hasData: false })
        })
    },
    goTixian(e){
        // Toast.success("提现功能暂未开放，敬请期待...");
        var accountId = e.currentTarget.dataset.item.id;
        var money = e.currentTarget.dataset.item.splitMoney;
        var isAdmin = e.currentTarget.dataset.item.isAdmin;
        if(isAdmin == 0){
            Toast.fail('您不是管理者不能提现');
        }else{
            wx.navigateTo({
                url: '/pagesMer/pages/tixian/index?id=' + accountId + "&money=" + money,
            })
        }
    },
    changeCurrent: function(t) {
        var e = t.detail.current;
        this.setData({
            current: e
        });
    },
    /**
     * 获取页面数据的 http请求
     */
    onHttpRecord: function () {
        var that = this
        fetchApi.httpPost('/account/record/list', {
            pageIndex:that.data.pageIndex,
            pageSize:that.data.pageSize,
        }, function (res) {
        console.log("账号记录数据", res)
        if(res.data.code == 0){
            if (res.data.totalcount > 0) {
                that.data.pageIndex = that.data.pageIndex + 1
                var records = res.data.data;
                if(records.length > 0){
                    for (var index in records) {
                        that.data.recordList.splice(that.data.recordList.length, 0, records[index]);
                    }
                    that.setData({
                        hasData: true,
                        recordList: that.data.recordList
                    })
                }
            }
        }
        that.setData({
            netWork: true,
        })
        }, function () {
            that.setData({ netWork: false, hasData: false })
        })
    },
})